import Vue from 'vue'
import VueRouter from 'vue-router'
import store from "@/store";

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: () => import('../views/ManageView.vue'),
    redirect: "/carMove",
    children: [
      { path: 'carMove', name: '小车运动', component: () => import('../views/CarMove.vue')},
      // { path: 'dataVisual', name: '武汉市数据可视化大屏', component: () => import('../views/DataVisualView.vue')},
      // { path: 'data', name: '数据', component: () => import('../views/DataView.vue')},
      { path: 'temperature', name: '温度', component: () => import('../views/DataTemperature.vue')},
      { path: 'humidity', name: '湿度', component: () => import('../views/DataHumidity.vue')},
      { path: 'illumination', name: '光照', component: () => import('../views/DataIllumination.vue')},
    ]
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  localStorage.setItem("currentPathName", to.name)  // 设置当前的路由名称，为了在Header组件中去使用
  store.commit("setPath")  // 触发store的数据更新
  next()  // 放行路由
})

export default router
